package it.uniroma2.art.coda.pdaexample;

import it.uniroma2.art.coda.interfaces.ProjectionRulesDeciderInterface;
import it.uniroma2.art.coda.projectionrule.ProjectionRule;
import it.uniroma2.art.coda.structures.SelectedProjectionRules;

import java.util.Collection;
import java.util.Iterator;
import java.util.Map;

import org.apache.uima.jcas.tcas.Annotation;

public class DefProjRulesDec extends ProjectionRulesDeciderInterface{
	
	public DefProjRulesDec(String id, String description) {
		super(id, description);
	}

	public SelectedProjectionRules invokeComponent() {
		SelectedProjectionRules selProjRules = new SelectedProjectionRules();
		Annotation ann = casAnn.getAnnotation();
		String annotationType = ann.getType().getName();
		Map<String, Collection<ProjectionRule>> prMap = prModel.getMapProjectionRules();
		Collection<ProjectionRule> prList = prMap.get(annotationType);
		if(prList == null)
			return selProjRules;
		Iterator<ProjectionRule> iterPR = prList.iterator();
		while(iterPR.hasNext()){
			ProjectionRule projRule = iterPR.next();
			selProjRules.addProjRule(projRule);
		}
		return selProjRules;
	}

}

